home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / textplugin_suggest.py < prev    next >
Text File  |  2009-08-31  |  2KB  |  95 lines

  1. #!BPY
  2. """
  3. Name: 'Suggest All | Ctrl Space'
  4. Blender: 246
  5. Group: 'TextPlugin'
  6. Shortcut: 'Ctrl+Space'
  7. Tooltip: 'Performs suggestions based on the context of the cursor'
  8. """
  9.  
  10. # Only run if we have the required modules
  11. try:
  12.     import bpy
  13.     from BPyTextPlugin import *
  14. except ImportError:
  15.     OK = False
  16. else:
  17.     OK = True
  18.  
  19. def check_membersuggest(line, c):
  20.     pos = line.rfind('.', 0, c)
  21.     if pos == -1:
  22.         return False
  23.     for s in line[pos+1:c]:
  24.         if not s.isalnum() and s != '_':
  25.             return False
  26.     return True
  27.  
  28. def check_imports(line, c):
  29.     pos = line.rfind('import ', 0, c)
  30.     if pos > -1:
  31.         for s in line[pos+7:c]:
  32.             if not s.isalnum() and s != '_':
  33.                 return False
  34.         return True
  35.     pos = line.rfind('from ', 0, c)
  36.     if pos > -1:
  37.         for s in line[pos+5:c]:
  38.             if not s.isalnum() and s != '_':
  39.                 return False
  40.         return True
  41.     return False
  42.  
  43. def main():
  44.     txt = bpy.data.texts.active
  45.     if not txt:
  46.         return
  47.     
  48.     line, c = current_line(txt)
  49.     
  50.     # Check we are in a normal context
  51.     if get_context(txt) != CTX_NORMAL:
  52.         return
  53.     
  54.     # Check the character preceding the cursor and execute the corresponding script
  55.     
  56.     if check_membersuggest(line, c):
  57.         import textplugin_membersuggest
  58.         textplugin_membersuggest.main()
  59.         return
  60.     
  61.     elif check_imports(line, c):
  62.         import textplugin_imports
  63.         textplugin_imports.main()
  64.         return
  65.     
  66.     # Otherwise we suggest globals, keywords, etc.
  67.     list = []
  68.     targets = get_targets(line, c)
  69.     desc = get_cached_descriptor(txt)
  70.     
  71.     for k in KEYWORDS:
  72.         list.append((k, 'k'))
  73.     
  74.     for k, v in get_builtins().items():
  75.         list.append((k, type_char(v)))
  76.     
  77.     for k, v in desc.imports.items():
  78.         list.append((k, type_char(v)))
  79.     
  80.     for k, v in desc.classes.items():
  81.         list.append((k, 'f'))
  82.     
  83.     for k, v in desc.defs.items():
  84.         list.append((k, 'f'))
  85.     
  86.     for k, v in desc.vars.items():
  87.         list.append((k, 'v'))
  88.     
  89.     list.sort(cmp = suggest_cmp)
  90.     txt.suggest(list, targets[-1])
  91.  
  92. # Check we are running as a script and not imported as a module
  93. if __name__ == "__main__" and OK:
  94.     main()
  95.